﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.Cms;
using Aij1.Model;
using Aij1.Utils;
using System.Text;
using System.Web.UI.HtmlControls;
using Aij1.BLL;

namespace Aij1
{
    public partial class Gallery : BasePage
    {
        protected A_Article A;
        protected string PrevLink, NextLink;
        protected void Page_Load(object sender, EventArgs e)
        {
            int albumId = CommOp.ToInt(Request.QueryString["Id"]);
            A = XpoSession.GetObjectByKey<A_Article>(albumId);

            if (A == null || (A.Status != ArticleStatusType.审核通过 && CurrentUser == null))
            {
                Response.Write("相册未找到.");
                Response.End();
                return;
            }
            else
            {
                PageName = A.Title;
            }

            PageName = A.Title;
            Keywords = A.Keywords;
            Description = CommOp.CutStr(A.Intro, 100);

            if (A.AType == ArticleType.新闻)
            {
                Response.Redirect("News.aspx?Id=" + A.Oid);
                Response.End();
            }
            A_Article prevNews = ArticleData.GetPrevNews(A, ArticleType.相册);

            PrevLink = QBind.GetAlbumHtml(prevNews, 100, 100).Replace(" target='_blank'", "");

            A_Article nextNews = ArticleData.GetNextNews(A, ArticleType.相册);

            NextLink = QBind.GetAlbumHtml(nextNews, 100, 100).Replace(" target='_blank'", ""); 
        }

        const string ImgStr = @"<li>
<a href='#p={0}' hidefocus='true'><img src='{1}'/></a>
<h2>{4}</h2>
<p>{2}</p>
<i title='img'>{3}</i>
<i title='timg'>{1}</i>
</li>
";
        public string ImgListStr()
        {
            StringBuilder sb = new StringBuilder();

            foreach (A_Photo p in A.Photos)
            {
                sb.AppendFormat(ImgStr, p.Oid, ResolveUrl(p.SnapShotUrl), CommOp.ToHtmlStr(p.Intro), ResolveUrl(p.Url), p.Title);
            }
            return sb.ToString();
        }
    }
}